package com.dkd.applet.controller;

import com.dkd.applet.domain.vo.SkuVo;
import com.dkd.applet.service.SkuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/vm")
@Slf4j
public class VendingMachineController {

    @Autowired
    private SkuService skuService;

    /**
     * 获取售货机商品列表
     *
     * @param innerCode
     * @return
     */
    @GetMapping("/skuList/{innerCode}")
    public List<SkuVo> getSkuListByInnerCode(@PathVariable String innerCode) {
        List<SkuVo> skuList = skuService.findSkuByInnerCode(innerCode);
        for (SkuVo sku : skuList) {
            // 检查是否已经有 "/profile" 前缀，如果没有才添加
            if (!sku.getImage().startsWith("/profile")) {
                sku.setImage("/profile" + sku.getImage());
            }
        }
        return skuList;
    }
}